package com.zhkj.txg.module.member.ui

import android.view.View
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.zhkj.lib.base.BaseActivity
import com.zhkj.txg.R
import kotlinx.android.synthetic.main.activity_member_rebate.*

class MemberRebateActivity : BaseActivity() {
    override val layoutResId: Int = R.layout.activity_member_rebate
    override fun statusTitleBar(): View? = titleMemberRebate

    private val allFragment: MemberRebateFragment by lazy {
        MemberRebateFragment.newInstance(0)
    }
    private val notRebateFragment: MemberRebateFragment by lazy {
        MemberRebateFragment.newInstance(1)
    }
    private val rebateFragment: MemberRebateFragment by lazy {
        MemberRebateFragment.newInstance(2)
    }

    override fun initUI() {
        with(vpMemberRebate) {
            adapter = object : FragmentStateAdapter(this@MemberRebateActivity) {
                override fun getItemCount(): Int = 3

                override fun createFragment(position: Int): Fragment = when (position) {
                    0 -> allFragment
                    1 -> notRebateFragment
                    else -> rebateFragment
                }
            }
            getChildAt(0)?.overScrollMode = View.OVER_SCROLL_NEVER
        }

        TabLayoutMediator(tabMemberRebate, vpMemberRebate, TabLayoutMediator.TabConfigurationStrategy { tab, position ->
            when (position) {
                0 -> tab.customView = layoutInflater.inflate(R.layout.item_collect_goods, null).apply {
                    findViewById<TextView>(R.id.tvGoods).text = getString(R.string.all)
                }
                1 -> tab.customView = layoutInflater.inflate(R.layout.item_collect_goods, null).apply {
                    findViewById<TextView>(R.id.tvGoods).text = getString(R.string.member_not_rebate)
                }
                2 -> tab.customView = layoutInflater.inflate(R.layout.item_collect_goods, null).apply {
                    findViewById<TextView>(R.id.tvGoods).text = getString(R.string.member_rebate)
                }
            }
        }).attach()
    }
}